package com.sgb.kjwl.viewmodel.self;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.user.AuthDetailEntity;
import com.sgb.kjwl.view.ui.activity.self.authentication.EnterpriseAuthDetailActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @Description
 * @Author huanglin
 * @Date 2020/12/10
 **/
public class EnterpriseAuthDetailModel extends BaseViewModel {

    private final EnterpriseAuthDetailActivity activity3;

    public EnterpriseAuthDetailModel(EnterpriseAuthDetailActivity activity3) {
        this.activity3 = activity3;
    }


    public void getUserInfo(String userNo) {
        DialogHelper.showProgressDialog(activity3, null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().getEnterpriseAuthDetail(userNo).enqueue(new Callback<BaseEntity<AuthDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<AuthDetailEntity>> call, Response<BaseEntity<AuthDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getData() == null) return;
                if (response.body().getState().equals("ok")) {
                    activity3.showDetail(response.body().getData());
                } else {
                    MToast.showToast(activity3, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<AuthDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

}
